<template>
	<view>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
			<swiper-item v-for="(item, i) in swiperList" :key="i">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- /轮播图 -->
		<!-- 导航栏 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, i) in navList" :key="i" @click="navClick(item)">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		<!-- /导航栏 -->
		<!-- 楼层 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item, i) in floorList" :key="i">
				<!-- 标题 -->
				<image :src="item.floor_title.image_src" mode="" class="floor-title"></image>
				<!-- /标题 -->
				<!-- 楼层产品 -->
				<view class="floor-img-box">
					<!-- 左侧 -->
					<navigator class="floor-img-left" :url="item.product_list[0].navigator_url">
						<image :src="item.product_list[0].image_src" mode="widthFix" :style="{ width: item.product_list[0].image_width + 'rpx'}"></image>
					</navigator>
					<!-- /左侧 -->
					<!-- 右侧 -->
					<view class="floor-img-right">
						<navigator class="img-right-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 !== 0" :url="item2.navigator_url">
							<image :src="item2.image_src" :style="{ width: item2.image_width + 'rpx'}" mode="widthFix"></image>
						</navigator>
					</view>
					<!-- /右侧 -->
				</view>
				<!-- /楼层产品 -->
			</view>			
		</view>
		<!-- /楼层 -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
        // 轮播图数据
				swiperList: [],
				// 分别导航的数据列表
				navList: [],
				// 楼层数据
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				 const { data } = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(data)
				if(data.meta.status !== 200) {
					return this.$showMsg()
				}
				this.swiperList = data.message
			},
			async getNavList() {
				const { data } = await uni.$http.get('/api/public/v1/home/catitems')
				if(data.meta.status !== 200) {
					return this.$showMsg()
				}
				this.navList = data.message
			},
			navClick(item) {
				// console.log(item)
				if(item.name === '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			async getFloorList() {
				const { data } = await uni.$http.get('/api/public/v1/home/floordata')
				if(data.meta.status !== 200) return this.$showMsg()
				console.log(data)
				data.message.forEach(floor => {
					floor.product_list.forEach(production => {
						production.navigator_url =  '/subpkg/goods_list/goods_list?' + production.navigator_url.split('?')[1]
					})
				})
				this.floorList = data.message
			}
		}
	}
</script>

<style lang="scss">
  swiper {
		height: 330rpx;
		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}
	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15rpx 0;
		image {
			width: 128rpx;
			height: 140rpx;
		}
	}
	.floor-title {
		height: 60rpx;
	}
	.floor-img-box {
		 display: flex;
		 padding: 0 10rpx;
		 .floor-img-right {
			 display: flex;
			 justify-content: space-around;
			 align-content: space-around;
			 flex-wrap: wrap;
		 }
	}
</style>
